package sunbao.ido.proxy;

import java.lang.reflect.Proxy;

/**
 * \* User: MeiZhongHao
 * \* Date: 2018-10-22
 * \* Time: 15:03
 * \* Description:
 * \
 */
public class IDoProxyFactory<T> {

    private final Class<T> iDoInterface;

    public IDoProxyFactory(Class<T> iDoInterface) {
        this.iDoInterface = iDoInterface;
    }

    protected <T> T newInstance(IDoProxy<T> proxy) {
        return (T) Proxy.newProxyInstance(this.iDoInterface.getClassLoader(), new Class[]{this.iDoInterface}, proxy);
    }

    public <T> T newInstance() {
        IDoProxy<T> proxy = new IDoProxy(this.iDoInterface);
        return this.newInstance(proxy);
    }
}